import java.net.*;

// Cliente de eco UDP

public class ClienteUDP {

	public static void main(String[] args) {
		String maquina = "localhost";
		int porto = 5000;
		String mensaxe = "OLA MANOLA";

		try {
			InetAddress enderezo = InetAddress.getByName(maquina);
			System.out.println(enderezo.toString());

			DatagramSocket socket = new DatagramSocket();

			socket.setSoTimeout(30000);
			socket.send(new DatagramPacket(mensaxe.getBytes(), mensaxe.length(), enderezo, porto));
			System.out.println("Mensaxe enviada... " + mensaxe);

			byte[] buf = new byte[200];
			socket.receive(new DatagramPacket(buf, 200));

			System.out.println("Mensaxe recibida... " + new String(buf));
			socket.close();

		} catch (Exception e) {
			System.err.println("Erro: " + e.getMessage());
			e.printStackTrace();
		}
	}
}
